<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>解决Promise类then函数返回Promise处理</title>
  <script src="./promise.js"></script>
</head>
<body>
  <ul>
    <li>首先对新返回的Promise按类型区分，如果是Promise需要再次通过then函数调用</li>
    <li>但注意当前实现很多冗余代码，需要重构(未解决)</li>
  </ul>
  <script>
    const promise = new MyPromise((resolve, reject) => {
      setTimeout(() => {
        resolve('success')
        // reject('fail')
      }, 1000)
    }).then(res => {
      // return 'miracle'
      return new MyPromise((resolve, reject) => {
        resolve('miracle')
      })
    }, err => console.log(err))
      .then(res => console.log(res), err => console.log(err))
  </script>
</body>
</html>